package cn.wolfcode.rbac.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 查询当前访问请求是否登录过
        if (request.getSession().getAttribute("EMPLOYEE_IN_SESSION")==null) {
            // 没有登录重定向到登录页面
            response.sendRedirect("/static/login.html");
            return false;
        }
        // 登录过就，放行访问
        return true;
    }
}
